package cn.school.controller.pay;


import cn.school.common.api.CommonPage;
import cn.school.common.api.CommonResult;
import cn.school.pay.service.ChargeItemService;
import cn.school.pay.vo.ChargeItemVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/chargeItem")
public class ChargeItemController {

    @Autowired
    private ChargeItemService chargeItemService;
    /**
     * 分页查询付费信息
     */
    @PostMapping("/pageList")
    public CommonResult<CommonPage<ChargeItemVO>> pageList(@RequestBody ChargeItemVO vo){
        IPage<ChargeItemVO> pageList = chargeItemService.pageList(vo);
        return CommonResult.success(CommonPage.restPage(pageList));
    }

    /**
     * 新增or修改付费信息
     * @param vo
     * @return
     */
    @PostMapping("/createOrUpdateCharge")
    public CommonResult<Integer> createOrUpdateCharge(@RequestBody ChargeItemVO vo){
        int num = chargeItemService.createOrUpdateCharge(vo);
        if(num>0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    /**
     * 根据ID删除付费信息
     * @param ids
     * @return
     */
    @PostMapping("/deleteById")
    public CommonResult<Integer> deleteById(@RequestBody List<Long> ids){
        int num = chargeItemService.deleteById(ids);
        if(num>0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }



}
